package com.example;

import java.time.LocalTime;

public class B1 {
    private boolean hasWater = true;
    private boolean isDamaged = false;
    private double temperature = 25.0;
    private boolean isHeating = false;

    public void start() {
        System.out.println("正在启动恒温水箱...");
        checkStatus();
    }

    public void checkStatus() {
        LocalTime now = LocalTime.now();
        int hour = now.getHour();

        if (hour >= 23 || hour < 7) {
            enterSleepMode();
        } else if (isDamaged) {
            repairTank();
        } else {
            maintainTemperature();
        }
    }

    private void maintainTemperature() {
        if (temperature < 20.0 && hasWater) {
            startHeating();
        } else if (temperature >= 100.0) {
            stopHeating();
        } else {
            System.out.println("温度处于正常范围：" + temperature + "°C。正在监控...");
        }
    }

    private void startHeating() {
        isHeating = true;
        System.out.println("加热开始...");
        temperature += 10.0; // 模拟温度上升
        System.out.println("当前温度：" + temperature + "°C");

        if (temperature >= 100.0) {
            stopHeating();
        }
    }

    private void stopHeating() {
        isHeating = false;
        System.out.println("加热停止，温度达到100°C。断开电源。");
    }

    private void enterSleepMode() {
        isHeating = false;
        System.out.println("进入休眠模式... 电源已断开。");
    }

    private void repairTank() {
        System.out.println("水箱损坏，正在修复...");
        isDamaged = false;
    }

    public void setDamaged(boolean damaged) {
        isDamaged = damaged;
    }

    public void setWater(boolean water) {
        hasWater = water;
    }

    public void setTemperature(double temp) {
        temperature = temp;
    }

    public static void main(String[] args) {
        B1 tank = new B1();
        tank.start();

        // 模拟不同的事件
        tank.setTemperature(15.0);
        tank.checkStatus();

        tank.setTemperature(100.0);
        tank.checkStatus();

        tank.setDamaged(true);
        tank.checkStatus();
    }
}
